// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#ifndef __H_MK_ENTITY_PARTICLE_SYSTEM__
#define __H_MK_ENTITY_PARTICLE_SYSTEM__

#include "mk_entity.h"

namespace MK3DE
{
	class CScene;
	class CParticleEmitter;
	class CParticleModifierColor;
	class CParticleModifierSize;
	class CTexture2D;

	class MK3DE_API CEntityParticleSystem : public CEntity
	{
	public:
		CEntityParticleSystem(CScene* pScene);
		~CEntityParticleSystem();

		//! Get entity render type and entity type.
		ENTITY_RENDER_TYPE GetRenderType() { return ERT_TRANSPARENT; }
		ENTITY_TYPE GetType() { return ET_PARTICLE_SYSTEM; }

		//! Load a particle system entity from file.
		BOOL LoadFromFile(const char* fileName);

		//! Enable or disable this entity.
		void Enable(BOOL bEnable) { _bEnable = bEnable; }
		BOOL IsEnable() { return _bEnable; }

		//! Set the texture file which is used by this entity.
		BOOL SetTextureName(const char* szTextureFileName);
		std::string GetTextureName();

		//! Set the texture cutting number.
		BOOL SetTextureCutting(DWORD dwCount);
		DWORD GetTextureCutting();

		//! Functions for accessing the particle emitter list.
		BOOL AddEmitter(/* out */ CParticleEmitter*& pEmitter);
		BOOL RemoveEmitter(CParticleEmitter* pEmitter);
		DWORD GetEmitterCount() { return (DWORD)_vecEmitter.size(); }
		CParticleEmitter* GetEmitter(DWORD idx);

		//! Update the entity.
		void Update(DWORD dt, BOOL bChanged);

		//! Render the entity.
		void Render();

	private:
		void __UpdateLocalAABB();
		void __Clean();

		BOOL __LoadEmitter(CParticleEmitter* pEmitter, TiXmlElement* node);
		BOOL __LoadParticleModifier(CParticleEmitter* pEmitter, TiXmlElement* node);
		BOOL __LoadParticleModifierColor(CParticleModifierColor* pModifier, TiXmlElement* node);
		BOOL __LoadParticleModifierSize(CParticleModifierSize* pModifier, TiXmlElement* node);

	private:
		BOOL _bEnable;

		std::vector<CParticleEmitter*> _vecEmitter;

		CTexture2D* _texture;
		DWORD _textureCutting;
	};
};

#endif // __H_MK_ENTITY_PARTICLE_SYSTEM__